<link type="text/css" href="/admins/js/pagerView/pager-view.css" rel="stylesheet" />
<link type="text/css" href="/admins/js/jquery/css/ui-lightness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
<script type="text/javascript" src="/admins/js/jquery/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="/admins/js/jquery/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript" src="/admins/js/pagerView/pager-view.js"></script>
<script type="text/javascript">
    $(function() {

        $.datepicker.setDefaults($.datepicker.regional[ "zh-CN" ]);
        $("#form1 #sel #starttime").datepicker({
            changeMonth: true,
            changeYear: true
        });
        $("#form1 #sel #endtime").datepicker({
            changeMonth: true,
            changeYear: true
        });
        $("#suborder #dateShip").datepicker({
            changeMonth: true,
            changeYear: true
        });
    });
</script>



<!-- 弹出div CSS -->
<style type="text/css">
    <!--
    .mydiv {
        background-color: #FFFFFF;
        border: 1px solid #000000;
        text-align: center;
        line-height: 40px;
        font-size: 12px;
        z-index:999;/*优先级*/
        width: 400px;
        height: 50px;
        left:50%;
        top:50%;
        margin-left:-150px!important;/*FF IE7 该值为本身宽的一半 ，!important的出现就是为了让用户自己设置被执行语句的优先级*/
        margin-top:-60px!important;/*FF IE7 该值为本身高的一半*/
        margin-top:0px;
        position:fixed!important;/* FF IE7*/
        position:absolute;/*IE6*/
    }
    
    a.indexa:visited{color:#c00}
    a.indexa:visited:hover{color:#f00}
    .popIframe {
        filter:alpha(opacity=0);/*IE 设置透明度*/
        opacity:0;/*FF*/
    }
    -->
</style>
<!-- 弹出div JS -->
<script language="javascript" type="text/javascript">
    function showDiv() {
        document.getElementById('popDiv').style.display = 'block';
        document.getElementById('popIframe').style.display = 'block';
        $(".houtai_overlay").show();
    }
    function closeDiv() {
        $(".tanchuang").hide();
        $("#popIframe").hide();
        $("#ProblemOrder").hide();
        $(".houtai_overlay").hide();
    }
    $(function() {
        $('.w0').dblclick(function() {
            $(this).css('background-color', '#fff')
        });

    });
</script>

<style>
    .datatable {
        width:90%;
        text-align: left;
        font-size: 12px;
        font-family: verdana;
        background: #c0c0c0; margin:2px;
    }

    .datatable thead tr,

    .datatable tfoot tr {
        background: #c0c0c0;
    }

    .datatable tbody tr {
        background: #f0f0f0;
        height: 30px;
    }

    .dataTable span{
        margin-left: 20px;
        font-size: 14px;
        vertical-align: middle;
    }
    #waybill-table td,#waybill-table th{
        border: 1px solid #000; 
        height:28px;
    }
    .datatable td {background-color:white;}

    .datatable .hover td {background-color:#99CCFF;}

    .datatable .select td {background-color:#EEEE99;}

    #ui-datepicker-div{ font-size:12px;}
    
    m{
        color: #c00;
    }
</style>
<div style="padding:2px; margin:2px;margin-left: 20px;" class="dataTable">
    <form action=""  method="get" style="margin:0px" id="form1">
        <div style=" border:1px solid #DDDDDD; padding:2px; margin:2px;line-height: 36px;" id='sel'> 
            <div>
                <label for="quick">快速搜索：</label><input type="text" id="quick" name="quick" value="<?php echo $this->quick; ?>" />
                <label for="starttime"><select id='seltime' name='seltime'>
                        <option value='createdTime' <?php echo $this->seltime=="createdTime"?"selected":""?>>创建时间</option>
                        <option value='paidTime' <?php echo $this->seltime=="paidTime"?"selected":""?>>付款时间</option>
                    </select>：</label>
                <input type="text" id="starttime" name="starttime" value="<?php echo $this->starttime; ?>" />
                <label for="endtime">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label><input type="text" id="endtime" name="endtime" value="<?php echo $this->endtime; ?>"  />  
                <label for="taobaoname">购买账户：</label><select id="taobaoname" name="taobaoname">
                    <option value="0" <?php echo $this->taobaoname==0?"selected":"";?>>所有</option>
                    <?php foreach ($this->taobaoAll as $taobaoVal) { ?>
                        <option value="<?php echo $taobaoVal->TaobaoSign;?>" <?php echo $this->taobaoname==$taobaoVal->TaobaoSign?"selected":"";?>><?php echo $taobaoVal->Taobaoname;?></option>
                    <?php }?> 
                </select>
                <input type="submit" id="queryButton" value="查询"/>
                <?php
                    echo $this->partial('paging.phtml', array("pages" => $this->result, "pamas" => "quick=" . $this->quick . "&starttime=$this->starttime&endtime=$this->endtime&status=$this->status&day=$this->day&myorder=$this->myorder&single=$this->single&problem=$this->problem&isdelete=$this->isdelete&seltime=$this->seltime&taobaoname=$this->taobaoname"));
                ?>
            </div>
        </div>

    </form>

    <div id="shipInfo" style="display:none;width: 560px">
        物流信息加载中,请稍候...
    </div>
    
    <table cellspacing="1" width="100%" border="1" class="datatable" id="waybill-table">
        <thead>
            <tr>
                <th class="w0">宝贝信息</th>
                <th class="w0">&nbsp;</th>
                <th class="w1">单价</th>
                <th class="w1">数量</th>
                <th class="w0">实付款</th>
                <th class="w1">状态</th>
            </tr>
        </thead>
        <tbody >

            <?php
            if ($this->buydetail != '') {
                foreach ($this->buydetail as $Item) {
                    $shopdetail = $Item->shipdetail;
                    ?>

                    <tr>
                        <td colspan="5" style="background-color: #DEF0FB;height: 20px;">
                            <?php if($Item->problem == Application_Model_Order::Problem_Appear || $Item->problem == Application_Model_Order::Problem_Complete){ ?>
                                <div class="ydtishi problem<?php echo $Item->Id;?>" style="float: left;">
                                    <a class="ts3<?php echo $Item->problem == Application_Model_Order::Problem_Complete?"_":""?> orderPrlblem<?php echo $Item->Id;?>" href="javascript:setProblem(<?php echo $Item->Id;?>)" title="问题包裹"></a>
                                </div>
                            <?php } ?>
                            <?php if($Item->Status == Application_Model_Order::STATUS_CONFRIM && $Item->Isdelete != 1){?>
                                <span>
                                    <input name="MergerCheck" type="checkbox" id="MergerCheck<?php echo $Item->Id;?>" value="<?php echo $Item->Id;?>" />
                                </span>
                            <?php }?>
                            <span>
                                订单编号：<a href="/admini/managebuyshop/buydetail/id/<?php echo $Item->Id;?>" class="indexa"><?php echo $Item->OrderNum; ?></a>
                                <?php if($Item->status == Application_Model_Order::STATUS_SELLER_SENDED || $Item->status == Application_Model_Order::STATUS_OUTTIME_INSTORE || $Item->status == Application_Model_Order::STATUS_INSTORE ){ ?>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="javascript:setOrderProblem(<?php echo $Item->id;?>)" id="orderProblem_<?php echo $Item->id;?>" class="indexa">收货异常</a>&nbsp;&nbsp;&nbsp;
                                <?php }?>
                            </span>
                            <?php if($Item->Status == Application_Model_Order::STATUS_PAYING){ ?>
                                <span>提交时间：<?php echo $Item->DateCreated; ?></span>
                            <?php } else { ?>
                                <span>付款时间：<?php echo $Item->datePaid; ?></span>
                            <?php } ?>
                            <span>用户ID：<?php echo $Item->userId; ?></span>
                            <span>仓库号：<a href="/admini/manageuser/userdetail/id/<?php echo $Item->userId; ?>" target="_blank" class="indexa"><?php echo 'F' . substr($Item->byuserdetail->storeno, 1); ?></a></span>
                            <span>昵称：<?php echo $Item->user->nikename; ?>(<?php echo $Item->user->email; ?>)</span>
                            <?php if($Item->user->CityId){ ?><span><font color="#0D6405"><?php echo $Item->user->cityname?$Item->user->cityname->Name:"未知"; ?></font></span><?php } ?>
                            <span>商品种类：<?php echo count($shopdetail); ?></span>
                            <span style="color:#c00;"><?php echo $Item->user->remark ? ("用户备注：" . (mb_strlen($Item->user->remark, 'utf-8') > 20 ? (mb_substr($Item->user->remark, 0, 20, 'utf-8') . '......') : $Item->user->remark)) : ""; ?></span>  
                            <span id="ShowOrHide<?php echo $Item->Id ?>" onclick="ShowOrHideProduct(<?php echo $Item->Id; ?>,<?php echo count($shopdetail); ?>)" style="cursor:pointer;color: red;">收起</span>
                        </td>
                        <td style="background-color: #DEF0FB;height: 20px;" align="center" id="OperTitle<?php echo $Item->id ?>">
                        <?php
                            if($Item->Isdelete != 1){
                            switch ($Item->status) {
                                case Application_Model_Order::STATUS_PAID:
                                ?>
                                <a href="javascript:SetConfrim(<?php echo $Item->id; ?>)" class="indexa">
                                    <div>设为已受理</div>
                                </a>
                        <?php
                                break;
                            case Application_Model_Order::STATUS_CONFRIM:
                        ?>
                            <a href="javascript:SetWaitShip(<?php echo $Item->id; ?>)" class="indexa">
                                <div>设为等待卖家发货</div>
                            </a>
                        <?php 
                                break;
                            case Application_Model_Order::STATUS_UNSEND:
                            case Application_Model_Order::STATUS_OUTTIME_UNSEND:
                            case Application_Model_Order::STATUS_SUBSCRIBE:
                        ?>
                            <a href="javascript:SetSeller(<?php echo $Item->id; ?>)" class="indexa">
                                <div>设为卖家已发货</div>
                            </a>
                        <?php 
                                break;
                            case Application_Model_Order::STATUS_SELLER_SENDED:
                            case Application_Model_Order::STATUS_OUTTIME_INSTORE:  
                        ?>
                            <a href="javascript:SetInStore(<?php echo $Item->id; ?>)" class="indexa">
                                <div>设为已入库</div>
                            </a>
                        <?php 
                                break;
                            } } ?>
                        </td>
                    </tr>
                    <?php echo "<tr id='tr_" . $Item->Id . "_1'>";
                        $index = 2; $shipUrl = "";?>
                    <?php
                    if ($shopdetail != null) {
                        foreach ($shopdetail as $key => $val) {
                            if (count($shopdetail) > 1) {
                                if ($key > 0) {
                                    echo "</tr><tr id='tr_" . $Item->Id . "_$index'>";
                                    $index+=1;
                                }
                            }
                            $productd = $val->byproductd;
                            if ($key == 0){
                                $shipUrl = $productd->url;
                            }
                            
                            $image = $productd->image ? $productd->image : $productd->remoteImage;
                            $arrimage = explode('"', $image);
                            if(count($arrimage)>1){
                                $imgUrl = $arrimage[1];
                            } else {
                                $imgUrl = $image;
                            }
                            ?>
                        <td valign="middle" class="w0">
                            <?php if ($Item->status != Application_Model_Order::STATUS_PAYING && $Item->status != Application_Model_Order::STATUS_PAID && $Item->status != Application_Model_Order::STATUS_CANCEL) { ?>
                                <?php if($Item->status == Application_Model_Order::STATUS_CONFRIM && $Item->operator != Uuch_Util::getUserNikeName()){?>
                                    <div style="float:left;">
                                        <img src="<?php echo $imgUrl; ?>" width="50px" height="50px" style="vertical-align:middle;"/>
                                    </div>
                                    <div style="float:left;">&nbsp;&nbsp;<?php echo $val->productName; ?></div><br>
                                    <div style="float:left;color:#666;">&nbsp;&nbsp;<?php echo $productd->PropertyAlias; ?></div>
                                <?php } else { ?>
                                    <div style="float:left;">
                                        <?php if($Item->Status == Application_Model_Order::STATUS_CONFRIM  && $Item->Isdelete != 1){?>
                                            <div style="float:left;font-size: 16px;margin-right: 10px;margin-top: 10px;">
                                                <input name="SplitCheck" type="checkbox" id="SplitCheck<?php echo $val->Id;?>" value="<?php echo $val->Id;?>" class="<?php echo $Item->Id;?>" <?php if(!(count($shopdetail) > 1) || $val->Status == 1){echo "disabled='true'"; }?>/>
                                                <span style="margin-left:5px;"><?php echo $key+1;?></span>
                                            </div>
                                        <?php } ?>
                                        <a href="<?php echo $val->taoBaoUrl?$val->taoBaoUrl:$productd->url; ?>" target="_blank">
                                            <img src="<?php echo $imgUrl; ?>" width="50px" height="50px" style="vertical-align:middle;"/>
                                        </a>
                                    </div>
                                    <div style="float:left;">
                                        &nbsp;&nbsp;<a href="<?php echo $val->taoBaoUrl?$val->taoBaoUrl:$productd->url; ?>" target="_blank" class="indexa"><?php echo $val->productName; ?></a>
                                    </div><br>
                                    <div style="float:left;color:#666;">&nbsp;&nbsp;<a href="<?php echo $productd->url ?>" target="_blank"><?php echo $productd->PropertyAlias; ?></a></div>
                                    
                                <?php } ?>
                            <?php } else { ?>
                                <div style="float:left;">
                                    <img src="<?php echo $imgUrl; ?>" width="50px" height="50px" style="vertical-align:middle;"/>
                                </div>
                                <div style="float:left;">&nbsp;&nbsp;<?php echo $val->productName; ?></div><br>
                                <div style="float:left;color:#666;">&nbsp;&nbsp;<?php echo $productd->PropertyAlias; ?></div>
                            <?php } ?>
                            <div style="float:left;color:#666;width: 950px;padding-left: 8px;">商品备注：<?php echo $val->comment ? $val->comment : "(无)"; ?></div><br>
                            <div style="float:left;color:#c00;margin-left: 50px;width: 950px;padding-left: 8px;" id="itemDescription<?php echo $val->id; ?>"><?php echo $val->description ? $val->description : ""; ?></div><br>

                        </td>

                        <td class="w1" align="center"><a href="javascript:AddRemarks(<?php echo $val->id; ?>);" class="indexa"><div id="Comment<?php echo $val->id; ?>">添加说明</div></a></td>

                        <td class="w1" align="center" id="returnMoney<?php echo $val->id; ?>"><?php echo $val->price; ?>
                            <?php
                            if ($val->status != 1) {
                                if ($Item->status != Application_Model_Order::STATUS_CANCEL && $Item->status != Application_Model_Order::STATUS_INSTORE && $Item->status != Application_Model_Order::STATUS_PAYING && $Item->status != Application_Model_Order::STATUS_PAID) {
                                    if( $Item->status == Application_Model_Order::STATUS_CONFRIM && $Item->operator == Uuch_Util::getUserNikeName()){
                                    ?>
                                    <a href="javascript:SingleRetuenMoney(<?php echo $val->id; ?>,<?php echo $Item->userId; ?>,<?php echo $val->price; ?>,<?php echo $val->quantity; ?>);"  class="indexa">
                                        <div id="SingleRetuenMoney<?php echo $val->id; ?>">单项退款</div></a>
                                    <?php } else if( $Item->status != Application_Model_Order::STATUS_CONFRIM) { ?>
                                    <a href="javascript:SingleRetuenMoney(<?php echo $val->id; ?>,<?php echo $Item->userId; ?>,<?php echo $val->price; ?>,<?php echo $val->quantity; ?>);"  class="indexa">
                                        <div id="SingleRetuenMoney<?php echo $val->id; ?>">单项退款</div></a>
                                <?php } }
                            } else {
                                ?>
                                <div><font color="green">已退款</font></div>
                                <?php
                            }
                            ?>
                        </td>
                        <td class="w0" align="center"><?php echo $val->quantity; ?></td>
                            <?php if ($key == 0) { ?>
                            <td class="w1" rowspan="<?php echo count($Item->shipdetail); ?>" align="center">￥<?php echo $Item->sum; ?> 
                                <?php if ((int) ($Item->shipFee) > 0) { echo "<br><font color='grey'>含运费：" . $Item->shipFee . "</font>"; } ?>
                            </td>
                            <td class="w0" rowspan="<?php echo count($Item->shipdetail); ?>"align="center" id="type<?php echo $Item->id; ?>">
                                <?php  if($Item->Isdelete != 1){ ?>
                                    <div id="statesname<?php echo $Item->id ?>" style="color:#229000;"><?php echo $Item->StatusNames; ?></div>
                                <?php
                                    if ($Item->status != Application_Model_Order::STATUS_BANK) {
                                        if ($Item->status != Application_Model_Order::STATUS_CANCEL && $Item->status != Application_Model_Order::STATUS_INSTORE && $Item->status != Application_Model_Order::STATUS_PAYING && $Item->status != Application_Model_Order::STATUS_PAID) {
                                            if($Item->status == Application_Model_Order::STATUS_CONFRIM && $Item->operator == Uuch_Util::getUserNikeName()){
                                            ?>
                                            <a href="javascript:ReturnMoney(<?php echo $Item->id; ?>,<?php echo $Item->userId ?>,<?php echo $Item->sum; ?>)" class="indexa" >取消并退款</a>
                                        <?php } else  if($Item->status != Application_Model_Order::STATUS_CONFRIM) { ?>
                                            <a href="javascript:ReturnMoney(<?php echo $Item->id; ?>,<?php echo $Item->userId ?>,<?php echo $Item->sum; ?>)" class="indexa" >取消并退款</a>
                                        <?php } }
                                } } else { ?>
                                    <div id="statesname<?php echo $Item->id ?>" style="color:#C00;">已删除</div>
                            <?php } ?>
                            </td>

                <?php }
            }
        } ?>
                </tr>

                <tr>
                    <td colspan="6" style="background-color: #FFFFFF;height: 20px;">
                        <?php if( $Item->Status == Application_Model_Order::STATUS_CONFRIM && $Item->Isdelete != 1){ ?>
                            <?php if((count($shopdetail) > 1)){ ?>
                                <span style="margin-right:10px;margin-left: 0px;"><a href="javascript:SplitOrder(<?php echo $Item->Id;?>)" class="indexa">拆分</a></span>
                            <?php } ?>
                            <span style="margin-right:10px;margin-left: 10px;"><a href="javascript:MergerOrder()" class="indexa">合并</a></span>
                        <?php } ?>
                            
                        淘宝订单编号：<input type="textbox" id="procureNo<?php echo $Item->id ?>" name="procureNo<?php echo $Item->id ?>" value="<?php echo $Item->procureNo; ?>" /> 物流单号：
                        <select name="logistics<?php echo $Item->id ?>" id="logistics<?php echo $Item->id ?>">
                            <option value="" ></option>
                        <?php foreach ($this->expresscomp as $expresscomp) { ?>
                                <option value="<?php echo $expresscomp->id; ?>" <?php if ($expresscomp->id == $Item->logistics) echo "selected" ?>><?php echo $expresscomp->word . '_' . $expresscomp->name; ?></option>
                        <?php } ?>
                        </select>
                        <input type="logisticsNo" id="logisticsNo<?php echo $Item->id ?>" name="logisticsNo<?php echo $Item->id ?>" value="<?php echo $Item->logisticsNo; ?>" /> <input type="button" id="btnLogistics<?php echo $Item->id ?>" name="btnLogistics<?php echo $Item->id ?>" onclick="javascript:UpdateLogistics(<?php echo $Item->id ?>)" value="更新" />
                        <?php if($Item->status == Application_Model_Order::STATUS_CONFRIM && $Item->operator != Uuch_Util::getUserNikeName()){ ?>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="javascript:editOperator(<?php echo $Item->id ?>)" id="editOperator<?php echo $Item->id ?>" class="indexa">更改受理人(<?php echo $Item->operator;?>)</a>
                        <?php } ?>
                            <a href="javascript:setProblem(<?php echo $Item->id ?>)" class="indexa">设置问题</a>
                        <?php if(($Item->procureNo != "" || $Item->procureNo != null)){ ?>                         
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="javascript:void(0)" id="tracklogistics" name="<?php echo $Item->id ?>">跟踪订单</a>                            
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <?php if($Item->status == Application_Model_Order::STATUS_UNSEND || $Item->status == Application_Model_Order::STATUS_OUTTIME_UNSEND || $Item->status == Application_Model_Order::STATUS_SUBSCRIBE){?>
                                <a href="javascript:orderSub(<?php echo $Item->id ?>)" id="orderSub<?php echo $Item->id ?>">订单预订</a>
                            <?php } ?>
                            <m <?php echo $Item->dateShip?"":"style='display:none;'";?> id="SubOrderShipDate<?php echo $Item->id ?>">(预订发货时间：<?php echo $Item->dateShip?$Item->dateShip:"";?>)</m>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <?php  
                                if(strpos($shipUrl,"taobao")>0 || strpos($shipUrl,"tmall")>0){
                                    $extendUrl = 'http://trade.taobao.com/trade/detail/trade_item_detail.htm?spm=a1z09.2.9.27.yegbD7&bizOrderId=' . $Item->procureNo;
                                } else {
                                    $extendUrl = $shipUrl;
                                }?>
                            <a href="<?php echo $extendUrl; ?>" target="_blank" class="indexa">
                                <?php echo $Item->procureNo?($Item->TaoBao?"(购买账号：".$Item->TaoBao->taobaoname.")":"订单跟踪"):""; ?>
                            </a>
                        <?php } ?>
                    </td>
                </tr>
                <tr  id="trProblem<?php echo $Item->id;?>" <?php echo ($Item->problem>Application_Model_Order::Problem_Default && $Item->problem<Application_Model_Order::Problem_Appear)?"":"style='display:none;'";?>>
                    <td id="tdProblem<?php echo $Item->id;?>" colspan="6" <?php echo $Item->problem>Application_Model_Order::Problem_Submit?"style='color:#f60;'":"style='color:#c00;'";?>>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;异常原因：<?php echo $Item->problemContent;?>
                        <span id="spanProblem<?php echo $Item->id;?>" <?php echo $Item->problem==Application_Model_Order::Problem_Solve?"style='color:#c00;'":"style='color:#c00;display:none;'";?>>---已解决</span>
                    </td>
                </tr>
                <tr>
                    <td colspan="6">&nbsp;</td>
                </tr>

            <?php
        }
    }
    ?>
        </tbody>
    </table>

<?php
echo $this->partial('paging.phtml', array("pages" => $this->result, "pamas" => "quick=" . $this->quick . "&starttime=$this->starttime&endtime=$this->endtime&status=$this->status&day=$this->day&myorder=$this->myorder&single=$this->single&problem=$this->problem&isdelete=$this->isdelete&seltime=$this->seltime&taobaoname=$this->taobaoname"));
?>
</div>


<div id="popDiv" class="tanchuang" style="display:none;height: 50px;">
    <table width="100%" height="100%" border="0">
        <tr height="100%">
            <td nowrap width="70px" align="right" style="padding-right: 5px;padding-top: 10px;">&nbsp;添加说明：</td>
            <td width="320px" align="left" nowrap style="padding-right: 5px;padding-top: 10px;">
                <input type="hidden" id="hidCommentId" />            
                <input type="textbox" id="txtComment" name="txtComment" style="width:250px"></input>
                <input type="button" id="btnSubmitComment" value="提交" onclick="SubmitComment()"/>
                <input type="button" id="btnSubmitComment" value="关闭" onclick="closeDiv()"/>
            </td>
        </tr>
    </table>
</div>
<div id="suborder" class="tanchuang" style="display:none;height: 50px;">
    <table width="100%" height="100%" border="0">
        <tr height="100%">
            <td nowrap width="100px" align="right"style="padding-right: 5px;padding-top: 10px;">&nbsp;订单预订发货时间：</td>
            <td width="320px" align="left" nowrap style="padding-right: 5px;padding-top: 10px;">
                <input type="hidden" id="hidSubOrderId" />            
                <input type="textbox" id="dateShip" name="dateShip" style="width:150px" readonly></input>
                <input type="button" id="btnSubmitSubDate" value="提交"  onclick="SubmitSubDate()"/>
                <input type="button" value="关闭" onclick="closeDiv()" />
            </td>
        </tr>
    </table>
</div>
<div id="orderProblem" class="tanchuang" style="display:none;height: 150px;">
    <table width="100%" height="100%" border="0">
        <tr height="100px">
            <td nowrap width="100px" align="right"style="padding-right: 5px;padding-top: 10px;">&nbsp;异常原因：</td>
            <td width="320px" align="left" nowrap style="padding-right: 5px;padding-top: 10px;">
                <input type="hidden" id="hidOrderProblemId" />            
                <textarea id="ProblemContent" name="ProblemContent" style="width:250px;height: 90px;"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <input type="button" id="btnSubmitProblemContent" value="提交"  onclick="SubmitProblemContent()"/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" value="关闭" onclick="closeDiv()" />
                <span style="display:none;" id="solveProblem">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:setSolveProblem()" class="indexa">异常解决</a>
                </span>
            </td>
        </tr>
    </table>
</div>
<div id="ProblemOrder" class="tanchuang" style="display:none;">
    <div class="nui-msgbox">
        <div class="nui-msgbox-hd" id="wayProblem">问题代购</div>
        <a class="nui-msgbox-close" title="关闭" onclick="closeDiv()"><b></b></a>
    </div>
    <div class="wt_top">
    	<div class="wt_nav">
            <ul>
            	<li class="wt_on"><a href="javascript:void(0)" id="problem">问题详情</a></li>
            </ul>
        </div>
    </div>
    <div class="wt_center" style="height:300px;">
            
    </div>
    <div class="wt_caozuo">
        <textarea name="content" cols="" rows="" id="content"></textarea>
        <input type="hidden" id="orderProblemId" name="orderProblemId" value="" />
        <a class="wt_liuyan" href="javascript:void(0);"><span>留言</span></a>
    </div>
    <a class="indexa SolveComplete" href="javascript:void(0);" style="float:right;margin-right: 20px;padding: 8px;"><span>问题解决</span></a>
</div>
<div class="houtai_overlay"  id='popIframe' style="display:none;"></div>
</body>

<script type="text/javascript">
    $('#waybill-table #accept').on('click', function() {
        var id = $(this).attr('name');
        if (id == '') {
            alert("请选择订单");
            return false;
        } else {
            $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/accept/id/' + id,
                success: function(data) {
                    if (data == 1) {
                        alert("受理成功");
                    } else if (data == 2) {
                        alert("受理只接受已付款的订单");
                    } else {
                        alert("发生未知错误，请重新操作");
                    }
                    location.href = '/admini/managebuyshop/index';
                }
            });

        }
    });
    $('#waybill-table #buyshop').on('click', function() {
        var id = $(this).attr('name');
        if (id == '') {
            alert("请选择订单");
            return false;
        } else {
            location.href = '/admini/managebuyshop/buyshop/id/' + id;
        }
    });
    $('#waybill-table #instore').on('click', function() {
        var id = $(this).attr('name');
        if (id == '') {
            alert("请选择订单");
            return false;
        } else {
            location.href = '/admini/managestore/instore/id/' + id;
        }
    });
    $('#waybill-table #shopout').on('click', function() {
        var id = $(this).attr('name');
        if (id == '') {
            alert("请选择订单");
            return false;
        } else {
            location.href = '/admini/managebuyshop/shopout/id/' + id;
        }
    });

    /**
     * 跟踪淘宝物流信息
     */
    $("#tracklogistics").live("click", function() {
        var id = $(this).attr("name");
        var tid = $("#procureNo" + id).val();
        $.post('/admini/managebuyshop/gettaobao', {'tid': tid}, function(sj) {
            if (sj.zt == 1) {
                $("#logistics" + id).find("option[value='" + sj.logisticsName + "']").attr("selected", true);
                $.each(sj.logistics, function(key, val) {
                    $("#logisticsNo" + id).val(val);
                    $("#btnLogistics" + id).click();
                });
            } else {
                alert("卖家没发货");
            }
        }, 'json');
    });
    /**
     *商品收起、展开
     **/
    function ShowOrHideProduct(orderId, trId)
    {
        for (var i = 1; i <= trId; i++)
        {
            if (document.getElementById("tr_" + orderId + "_" + i).style.display == "none")
            {
                $("#tr_" + orderId + "_" + i).show();
                $("#ShowOrHide" + orderId).html("收起");
                $("OrderPrice" + orderId).attr("rowspan", "0");
            }
            else
            {
                $("#tr_" + orderId + "_" + i).hide();
                $("#ShowOrHide" + orderId).html("展开");
                $("OrderPrice" + orderId).attr("rowspan", trId);
            }
        }
    }

    /**
     *提交说明
     */
    function SubmitComment()
    {
        var comment = $("#txtComment").val();
        var id = $("#hidCommentId").val();
        if (comment == '')
        {
            alert("请输入说明信息.");
            return;
        }

        $("#btnSubmitComment").html('提交中...');
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/updateorderitemcomment/id/' + id + '/comment/' + comment,
            success: function(data) {
                if (data == 1) {
                    alert("提交成功");
                    $("#btnSubmitComment").html('提交');
                    $("#itemDescription" + id).text(comment);
                    closeDiv();
                } else {
                    alert("发生未知错误，请重新操作");
                }
            }
        });
    }
    /**
     * 提交预付时间
     * @param {type} id
     */
    function SubmitSubDate()
    {
        var id = $("#hidSubOrderId").val();
        var dateShip = $("#dateShip").val();
        if(dateShip == ""){
            alert("请选择预订发货的时间。");
            return false;
        }
        if(confirm("您确定该代购为预订订单，发货时间为"+dateShip+"？","提示信息")){   
            $("#btnSubmitSubDate").html('提交中...');
            $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/updateordershipdate/id/' + id + '/dateShip/' + dateShip,
                success: function(data) {
                    if (data == 1) {
                        alert("提交成功");
                        $("#btnSubmitSubDate").html('提交');
                        $("#SubOrderShipDate" + id).text("(预订发货时间："+ dateShip+")");
                        $("#SubOrderShipDate" + id).show();
                        closeDiv();
                    } else {
                        alert("发生未知错误，请重新操作");
                    }
                }
            });
        }
    }
    /**
     *添加说明
     */
    function AddRemarks(id)
    {
        $("#hidCommentId").val(id);

        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/getcomment/id/' + id,
            success: function(data) {
                $("#txtComment").val(data);
            }
        });

        showDiv();
    }
    function SetConfrim(id)
    {
        $("#OperTitle"+id).text("正在受理···");
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/setconfrim/id/' + id,
            success: function(data) {
                if(data == 1){
                    $("#OperTitle"+id).text("受理成功");
                }else{
                    alert("发生未知错误。")
                }
            }
        });
    }
    function SetWaitShip(id)
    {
        $("#OperTitle"+id).text("正在下单···");
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/setwaitship/id/' + id,
            success: function(data) {
                if(data == 1){
                    $("#OperTitle"+id).text("下单成功");
                }else if (data == 2){
                    $("#OperTitle"+id).html('<a href="javascript:SetWaitShip('+id+')" class="indexa"><div>设为等待卖家发货</div></a>');
                    alert("下单订单编号不能为空");
                }else{
                    alert("发生未知错误。")
                }
            }
        });
    }
    
    function SetSeller(id)
    {
        $("#OperTitle"+id).text("正在设置···");
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/setseller/id/' + id,
            success: function(data) {
                if(data == 1){
                    $("#OperTitle"+id).text("设置成功");
                }else if (data == 2){
                    $("#OperTitle"+id).html('<a href="javascript:SetSeller('+id+')" class="indexa"><div>设为卖家已发货</div></a>');
                    alert("卖家发货的物流信息不能为空");
                }else{
                    alert("发生未知错误。")
                }
            }
        });
    }
    
    function orderSub(id)
    {
        $("#hidSubOrderId").val(id);
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/getdateShip/id/' + id,
            success: function(data) {
                $("#dateShip").val(data);
            }
        });
        $("#suborder").show();
        $("#popIframe").show();
        $(".houtai_overlay").show();
    }
    
    function SetInStore(id)
    { 
        $("#OperTitle"+id).text("正在设置···");
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/setinstore/id/' + id,
            success: function(data) {
                if(data == 1){
                    $("#OperTitle"+id).text("设置成功");
                }else if (data == 2){
                    $("#OperTitle"+id).html('<a href="javascript:SetInStore('+id+')" class="indexa"><div>设为已入库</div></a>');
                    alert("该商品还没有入库");
                }else{
                    alert("发生未知错误。")
                }
            }
        });
    }
    
    function editOperator(id)
    {
        if(confirm("您确定该代购的受理人更改为您？","提示信息")){  
            $("#editOperator"+id).text("更改中···");
            $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/editoperator/id/' + id,
                success: function(data) {
                    if(data == 1){
                        $("#editOperator"+id).text("更改成功");
                    }else{
                        alert("发生未知错误。")
                    }
                }
            });
        }
    }
    
    function setOrderProblem(id)
    {
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/getproblemcontent/id/' + id,
            success: function(data) {
                if(data.status == 1){
                    $("#ProblemContent").val(data.problemcontent);
                    if(data.problemtype == 1){
                        $("#solveProblem").show();
                    }else{
                        $("#solveProblem").hide();
                    }
                }else{
                    $("#solveProblem").hide();
                }
            }
        });
        $("#hidOrderProblemId").val(id);
        $("#orderProblem").show();
        $(".houtai_overlay").show();
    }
    
    function SubmitProblemContent()
    {
        var id = $("#hidOrderProblemId").val();
        var problemcontent = $("#ProblemContent").val();
        if(problemcontent == ""){
            alert("请填写异常原因");
            return false;
        }
        
        if(confirm("您确定该代购订单出现异常？","提示信息")){ 
            $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/addproblemcontent/id/' + id+"/problemcontent/"+problemcontent,
                success: function(data) {
                    if(data == 1){ 
                        $("#tdProblem"+id).attr("style","color:#c00;");
                        $("#tdProblem"+id).html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;异常原因："+problemcontent+"<span id='spanProblem"+id+"' style='display:none;color:#c00;'>---已解决</span>");
                        $("#trProblem"+id).show();
                        closeDiv();
                    }else{
                        alert("出现未知错误");
                    }
                }
            });
        }
    }
    
    function setSolveProblem()
    {
        var id = $("#hidOrderProblemId").val();
        if(confirm("您确定该异常代购订单异常已经解决？","提示信息")){ 
            $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/solveproblem/id/' + id,
                success: function(data) {
                    if(data == 1){ 
                        $("#tdProblem"+id).attr("style","color:#f60;");
                        $("#spanProblem"+id).show();
                        closeDiv();
                    }else{
                        alert("出现未知错误");
                    }
                }
            });
        }
    }
    /**
     *更改状态
     */
    function UpdateStatu(orderId, statu)
    {
        var restatus = "";
        $("#OperTitle" + orderId).html('设置中...');
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/updatestatu/orderId/' + orderId + '/statu/' + statu,
            success: function(data) {
                if (data == 1) {
                    switch (statu) {
                        case <?php echo Application_Model_Order::STATUS_PAID; ?>:
                            restatus = <?php echo Application_Model_Order::STATUS_CONFRIM; ?>;
                            $("#OperTitle" + orderId).html("<?php echo '设为' . Application_model_order::getStatusDescription(Application_Model_Order::STATUS_CONFRIM); ?>");
                            $("#updateOrderType" + orderId).attr("href", "javascript:UpdateStatu(" + orderId + ",<?php echo Application_Model_Order::STATUS_CONFRIM; ?>)");
                            $("#statesname" + orderId).html("");
                            break;
                        case <?php echo Application_Model_Order::STATUS_CONFRIM; ?>:
                            restatus = <?php echo Application_Model_Order::STATUS_UNSEND; ?>;
                            $("#OperTitle" + orderId).html("<?php echo '设为' . Application_model_order::getStatusDescription(Application_Model_Order::STATUS_UNSEND); ?>");
                            $("#updateOrderType" + orderId).attr("href", "javascript:UpdateStatu(" + orderId + ",<?php echo Application_Model_Order::STATUS_UNSEND; ?>)");
                            $("#statesname" + orderId).html("已受理");
                            break;
                        case <?php echo Application_Model_Order::STATUS_UNSEND; ?>:
                            restatus = <?php echo Application_Model_Order::STATUS_SELLER_SENDED; ?>;
                            $("#OperTitle" + orderId).html("<?php echo '设为' . Application_model_order::getStatusDescription(Application_Model_Order::STATUS_SELLER_SENDED); ?>");
                            $("#updateOrderType" + orderId).attr("href", "javascript:UpdateStatu(" + orderId + ",<?php echo Application_Model_Order::STATUS_SELLER_SENDED; ?>)");
                            $("#statesname" + orderId).html("等待卖家发货");
                            break;
                        case <?php echo Application_Model_Order::STATUS_SELLER_SENDED; ?>:
                            restatus = <?php echo Application_Model_Order::STATUS_INSTORE; ?>;
                            $("#OperTitle" + orderId).html("<?php echo '设为' . Application_model_order::getStatusDescription(Application_Model_Order::STATUS_INSTORE); ?>");
                            $("#updateOrderType" + orderId).attr("href", "javascript:UpdateStatu(" + orderId + ",<?php echo Application_Model_Order::STATUS_INSTORE; ?>)");
                            $("#statesname" + orderId).html("卖家已发货");
                            break;
                        case <?php echo Application_Model_Order::STATUS_INSTORE; ?>:
                            restatus = <?php echo Application_Model_Order::STATUS_CANCEL; ?>;
                            $("#OperTitle" + orderId).html("<?php echo '设为' . Application_model_order::getStatusDescription(Application_Model_Order::STATUS_CANCEL); ?>");
                            $("#updateOrderType" + orderId).attr("href", "javascript:UpdateStatu(" + orderId + ",<?php echo Application_Model_Order::STATUS_CANCEL; ?>)");
                            $("#statesname" + orderId).html("已入库");
                            break;
                        default :
                            restatus = 999;
                            $("#OperTitle" + orderId).html("");
                            $("#statesname" + orderId).html("已取消");
                            break;
                    }
                } else if (data == 2) {
                    alert("淘宝订单编号为空，不能设为等待卖家发货！");
                    $("#OperTitle" + orderId).html('设为等待卖家发货');
                } else {
                    alert("发生未知错误，请重新操作");
                }
            }
        });
    }

    /**
     *更改物流信息
     */
    function UpdateLogistics(id)
    {
        var procureNo = $("#procureNo" + id).val();
        var logistics = $("#logistics" + id).val();
        var logisticsNo = $("#logisticsNo" + id).val();

        $("#btnLogistics" + id).val('更新中...');
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/updatelogistics/id/' + id + '/procureNo/' + procureNo + '/logistics/' + logistics + '/logisticsNo/' + logisticsNo,
            success: function(data) {
                if (data == 1) {
                    $("#btnLogistics" + id).val('更新成功');
                    $("#procureNo" + id).val(procureNo);
                    $("#logistics" + id + " option[value='" + logistics + "']").attr("selected", "selected");
                    $("#logisticsNo" + id).val(logisticsNo);
                } else if (data == 2) {
                    alert("物流单号已存在");
                    $("#btnLogistics" + id).val('更新');
                } else if (data == 3) {
                    alert("该订单不是你受理的，你不能更新该订单的下单订单编号。");
                    $("#btnLogistics" + id).val('更新');
                } else {
                    alert("发生未知错误，请重新操作");
                }
            }
        });
    }

    /**
     * 单个商品退款
     */
    function SingleRetuenMoney(id, userid, price, num)
    {
        var total = accMul(price, num);
        if (confirm("您确定该代购商品取消并退款" + total + "元", "提示信息")) {
            $.post('/admini/managebuyshop/countorder', {'id': id}, function(sj) {
                if (sj == 1) {
                    if (confirm("退款过程中是否退运费", "提示信息")) {
                        num = 1;
                        $.ajax({
                            type: 'POST',
                            url: '/admini/managebuyshop/singleretuenmoney/id/' + id + '/userid/' + userid + '/num/1',
                            success: function(data) {
                                if (data == 1) {
                                    alert("退款成功");
                                    var html = price + '<div><font color="green">已退款</font></div>';
                                    $("#returnMoney" + id).html(html);
                                    $("#SplitCheck"+id).attr("disabled","true");
                                } else {
                                    alert("发生未知错误，请重新操作");
                                }
                            }
                        });
                    } else {
                        $.ajax({
                            type: 'POST',
                            url: '/admini/managebuyshop/singleretuenmoney/id/' + id + '/userid/' + userid + '/num/0',
                            success: function(data) {
                                if (data == 1) {
                                    alert("退款成功");
                                    var html = price + '<div><font color="green">已退款</font></div>';
                                    $("#returnMoney" + id).html(html);
                                    $("#SplitCheck"+id).attr("disabled","true");
                                } else {
                                    alert("发生未知错误，请重新操作");
                                }
                            }
                        });
                    }
                } else {
                    $.ajax({
                        type: 'POST',
                        url: '/admini/managebuyshop/singleretuenmoney/id/' + id + '/userid/' + userid + '/num/0',
                        success: function(data) {
                            if (data == 1) {
                                alert("退款成功");
                                var html = price + '<div><font color="green">已退款</font></div>';
                                $("#returnMoney" + id).html(html);
                                $("#SplitCheck"+id).attr("disabled","true");
                            } else {
                                alert("发生未知错误，请重新操作");
                            }
                        }
                    });
                }
            }, 'json');

        }
    }

    /**
     * 整个订单退款
     */
    function ReturnMoney(id, userid, total)
    {
        if (confirm("您确定该代购取消并退款" + total + "元", "提示信息")) {
            $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/retuenmoney/id/' + id + '/userid/' + userid,
                success: function(data) {
                    if (data.status == 1) {
                        alert("退款成功");
                        $.each(data.resj, function(key, val) {
                            var html = val + '<div><font color="green">已退款</font></div>';
                            $("#returnMoney" + key).html(html);
                            $("#type" + id).html("已取消");
                            $("#type" + id).attr("style", "color:#229000;")
                        });
                    } else {
                        alert("发生未知错误，请重新操作");
                    }
                    //location.href='/admini/managebuyshop/index/stus/<?php //echo $this->status ?>';
                }
            });
        }
    }
    
    /**
     * 拆分
     */
    function SplitOrder(orderId)
    {
        var idlist = '';
        $('input[class="'+orderId+'"]:checked').each(function(){    
             if($(this).attr("disabled") != "true"){
		idlist+= $(this).val()+',';
             }else{
                 alert("对不起，您选择的订单不能拆分");
             }
	});
        if(idlist == ""){
            alert("请选择需要拆分的商品！");
            return ;
        }
        if (confirm("您确定拆分该代购订单", "提示信息")) {
            $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/splitorder/id/' + orderId + '/itemlist/' + idlist,
                success: function(data) {
                    if (data == 1) {
                        alert("拆分成功");
                        location.reload();
                    } else if(data == 2) {
                        alert("只能拆分受理订单");
                    } else if(data == 3) {
                        alert("不能拆分所有的下级商品");
                    } else {
                        alert("发生未知错误，请重新操作");
                    }
                }
            });
        }
    }
    /**
     * 合并
     */
    function MergerOrder() 
    {
        var idlist = '';
        var i = 0;
        $('input[name="MergerCheck"]:checked').each(function(){   
            idlist+= $(this).val()+',';
            i++;
	});
        if(idlist == ""){
            alert("请选择需要合并的运单！");
            return ;
        }
        if(i == 1){
            alert("一个订单无法合并！");
            return ;
        }
        if (confirm("您确定合并该代购订单", "提示信息")) {
            $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/mergerorder/itemlist/' + idlist,
                success: function(data) {
                    if (data == 1) {
                        alert("合并成功");
                        location.reload();
                    } else if(data == 2) {
                        alert("只能合并受理订单");
                    } else if(data == 3) {
                        alert("不能合并不同客户的订单");
                    } else if(data == 4) {
                        alert("一个订单无法合并");
                    } else if(data == 5) {
                        alert("无法合并已经删除的订单");
                    } else {
                        alert("发生未知错误，请重新操作");
                    }
                }
            });
        }
    }
    
    /**
     * 设置问题展示
     */
    function setProblem(orderId)
    {
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/problemshow/orderId/' + orderId,
            success: function(data) {
                if (data.type == 1) {
                    var html = "";
                    $.each(data.arrProblem, function(key, val) {
                        html += '<div class="'+(val.issueetype==1?'wt_uuch':'wt_kehu')+'">';
                        html += '<h2>'+(val.issueetype==1?'悠奇客服':('回复人：<a href="/admini/manageuser/userdetail/id/'+val.userId+'" target="_blank">'+val.userName+'</a>'));
                        html += '<span>'+val.dateCreated+'</span></h2>';
                        html += '<p>'+val.content+'</p></div>';
                    });
                    $("#ProblemOrder .wt_center").html(html);
                    $("#orderProblemId").val(orderId);
                    $("#ProblemOrder").show();
                    $(".houtai_overlay").show();
                } else {
                    alert("发生未知错误，请重新操作");
                }
            }
        });
    }
    
    $(".SolveComplete").click(function(){
        var orderId = $("#orderProblemId").val();
        $.ajax({
            type: 'POST',
            url: '/admini/managebuyshop/solvecomplete/orderId/' + orderId,
            success: function(data) {
                if (data == 1) {
                    alert("问题解决成功");
                    $(".orderPrlblem"+orderId).removeClass("ts3").addClass("ts3_");
                } else {
                    alert("发生未知错误，请重新操作");
                }
            }
        });
    });
    
    $(".wt_liuyan").click(function(){
        var orderProblemId = $("#orderProblemId").val();
        var content = $("#content").val();
        $.post('/admini/managebuyshop/addorderpb/orderProblemId/'+orderProblemId,{"content":content},function(data){
            if(data ==1){
                    alert("设置成功！");
                    $(".problem"+orderProblemId).show();
                    $("#content").val("");
                    $("#orderProblemId").val("");
                    closeDiv();
                }else{
                    alert("发生未知错误，请重新操作");
                }
        });
    });
    function accMul(arg1, arg2) {
        var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
        try {
            m += s1.split(".")[1].length
        } catch (e) {
        }
        try {
            m += s2.split(".")[1].length
        } catch (e) {
        }
        return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
    }

</script>
